#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int trap(int* height, int heightSize)
{
    int ret = 0;
    int left = 0;
    int right = heightSize - 1;
    int leftmax = 0;
    int rightmax = 0;
    while (left < right)
    {
        leftmax = fmax(leftmax, height[left]);
        rightmax = fmax(rightmax, height[right]);
        if (height[left] < height[right])
        {
            ret += leftmax - height[left];
            left++;
        }
        else
        {
            ret += rightmax - height[right];
            right--;
        }
    }
    return ret;
}